package com.dog.view.controller;

import com.dog.model.Role;
import com.dog.service.IRoleService;
import com.dog.spring.ServiceFactory;
import com.dog.view.beans.BaseBean;
import com.dog.view.beans.RoleBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.context.WebApplicationContext;

import javax.annotation.PostConstruct;
import javax.faces.model.SelectItem;

/**
 * User: Kuttubek Aidaraliev
 * Date: 06.05.2010
 * Time: 16:21:17
 */
@Controller
@Scope(value= WebApplicationContext.SCOPE_REQUEST)
public class RoleBeanController extends BaseBeanController<IRoleService, Role, RoleBean> {

    @Autowired
    private IRoleService roleService;

    public RoleBeanController() {
    }

    @PostConstruct
    protected void initialized(){
       IRoleService roleService = ServiceFactory.getRoleService();
       setService(roleService);
    }

    @Override
    public String inserted(){
        super.inserted();
        return view();
    }

    @Override
    public String list(){
        return "roleList";
    }

    @Override
    protected String form() {
        return "role";
    }

    @Override
    protected Role newEntity() {
        return new Role();
    }

    @Override
    protected SelectItem createSelectItem(Role role) {
        return new SelectItem(role, role.getTitle());  
    }

    @Override
    protected String getNameEntity() {
        return "roleBean";
    }

    @Override
    protected RoleBean createEntityBean() {
        return new RoleBean();
    }

}